package com.mission.game.utils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

public class User implements Serializable {
	private static final long serialVersionUID = -4265608606869608931L;
	private String _name;
	private String _pass;
	private int _globalScore;
	private HashMap<String, Game> _games;
	private HashMap<String, Game> _oldGames;
	private HashMap<String, Game> _myGames;

	public User(String name, String pass) {
		_name = name;
		_pass = pass;
		_globalScore = 0;
		_games = new HashMap<String, Game>();
		_myGames = new HashMap<String, Game>();
		_oldGames = new HashMap<String, Game>();
	}

	public String getName() {
		return _name;
	}

	public void setName(String name) {
		_name = name;
	}

	public int getGlobalScore() {
		return _globalScore;
	}

	public void setGlobalScore(int globalScore) {
		_globalScore = globalScore;
	}

	public String getPass() {
		return _pass;
	}

	public void setPass(String pass) {
		_pass = pass;
	}

	public HashMap<String, Game> getGames() {
		return _games;
	}

	public HashMap<String, Game> getOldGames() {
		return _oldGames;
	}

	public HashMap<String, Game> getMyGames() {
		return _myGames;
	}

	public void addNewGame(Game game) {
		_games.put(game.getName(), game);
	}

	public ArrayList<String> getGameNames() {
		ArrayList<String> names = new ArrayList<String>();
		for (Game game : _games.values()) {
			if (game.isActive()) {
				names.add(game.getName());
			}
		}
		return names;
	}

	public ArrayList<String> getInviteGameNames() {
		ArrayList<String> names = new ArrayList<String>();
		for (Game game : _games.values()) {
			if (!game.isActive()) {
				names.add(game.getName());
			}
		}
		return names;
	}

	public Game getGame(String gameName) {
		return _games.get(gameName);
	}

	public void acceptInvitation(String invitation) {
		_games.get(invitation).setIsActive(true);
	}

	public void updateGame(Game game) {
		_games.put(game.getName(), game);
	}

	public void removeGame(String game) {
		_games.remove(game);
	}
}
